package com.edu.test;

import com.edu.bean.User;
import com.edu.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Scanner;

public class MyTest2 {

    public static void main(String[] args) {
        ApplicationContext app = new ClassPathXmlApplicationContext("app.xml");
        UserService userService = app.getBean(UserService.class);
        System.out.println("请输入用户名:");
        Scanner scanner = new Scanner(System.in);
        User user = new User();
        String userName = scanner.next();
        user.setUserName(userName);
        System.out.println("请输入密码");
        String password = scanner.next();
        user.setPassword(password);
        User userByNamePass = userService.getUserByNamePass(user);
        try {
            if (userByNamePass.getUserId() > 0) {
                System.out.println("登录成功");
            }
        }catch (Exception e){
            User userByName = userService.getUserByName(userName);
            try {
                if(userByName.getUserId() > 0){
                    System.out.println("密码错误");
                }
            }catch (Exception f){
                System.out.println("用户名不存在");
            }
        }
    }
}
